package hong.jun.lock;

import hong.jun.task.ThreadTask;


/**
 * 说明:战斗任务线程
 * Created on 2023/10/19 15:12
 *
 * @author yanghongjun <1737619387@qq.com>
 */
public class ThreadLockTask extends ThreadTask {

    private final LockData lockData;

    public ThreadLockTask(LockData lockData) {
        this.lockData = lockData;
    }

    /**
     * @Description:
     * @Param: []
     * @return: void
     * @Author: yanghongjun
     * @Date: 2023/10/19
     */
    @Override
    protected void action() {
        String threadName = Thread.currentThread().getName();
        lockData.lock();//写加锁
        try {
            int count = lockData.getCount();
            lockData.setCount(++count);
            System.out.println(threadName + "a:" + lockData.getCount());
        } finally {
            lockData.unlock();//写解锁
        }
    }


}
